import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_shop/provide/cart.dart';
import 'package:provide/provide.dart';

class CartBootom extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Container(
      width: ScreenUtil().setWidth(750.0),
      decoration: BoxDecoration(
          border: Border(
        top: BorderSide(color: Colors.black12, width: 0.5),
      )),
      child: Row(
        children: <Widget>[
          _cart_checkBox(),
          _priceAndBotton(),
        ],
      ),
    );
  }

  //Checkbox 按钮
  Widget _cart_checkBox() {
    return Provide<CartProvide>(
      builder: (context,child,cartInfo){
        return Container(
          width: ScreenUtil().setWidth(200.0),
          alignment: Alignment.center,
          padding: EdgeInsets.fromLTRB(10.0, 5.0, 10.0, 5.0),
          height: ScreenUtil().setHeight(80.0),
          child: Row(
            children: <Widget>[
              Checkbox(
                value: cartInfo.isAllChange,
                onChanged: (bool val) {

                  Provide.value<CartProvide>(context).changeAll();
                },
                activeColor: Colors.pink,
              ),
              Text(
                '全选',
                style: TextStyle(
                  fontSize: ScreenUtil().setSp(25.0),
                ),
              )
            ],
          ),
        );
      },
    );
  }

  //价格和结算按钮
  Widget _priceAndBotton() {
    return Container(
      width: ScreenUtil().setWidth(550.0),
      child: Row(
        children: <Widget>[
          _cartPrice(),
          _priceBottom(),
        ],
      ),
    );
  }

  //价格
  Widget _cartPrice() {
    return Container(
      padding: EdgeInsets.only(right: 10.0),
      width: ScreenUtil().setWidth(400.0),
      child: Column(
        children: <Widget>[
          Provide<CartProvide>(
            builder: (context,child,cartInfo){
              return Container(
                alignment: Alignment.topRight,
                child: Text(
                  '合计：￥${cartInfo.AllPrice}',
                  style: TextStyle(
                    color: Colors.pink,fontSize: ScreenUtil().setSp(25.0),
                  ),
                ),
              );
            },
          ),
        Container(
          alignment: Alignment.topRight,
          child:Text(
            '不含运费',
            style: TextStyle(
              color: Colors.black26,
              fontSize: ScreenUtil().setSp(18.0),
            ),
          ),
        )
        ],
      ),
    );
  }

  //结算按钮
  Widget _priceBottom(){
    return Provide<CartProvide>(
      builder: (context,child,cartInfo){
        return Container(
          alignment: Alignment.center,
          height: ScreenUtil().setHeight(80.0),
          width: ScreenUtil().setWidth(150.0),
          padding: EdgeInsets.fromLTRB(10.0, 5.0, 10.0, 5.0),
          decoration: BoxDecoration(
              color: Colors.pink
          ),
          child:InkWell(
            child:Text(
              '结算(${cartInfo.AllGoodsCount})',
              style: TextStyle(
                color: Colors.white,
                fontSize: ScreenUtil().setSp(28.0),
              ),
            ),
          ),
        );
      },
    );
  }
}
